package com.ding.easycontroller.utils;

import com.ding.easycontroller.bean.ConsoleWork;

import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingDeque;

public class ConsoleUtils {


    private static ConsoleWork console;

    //使用队列执行任务
    private static BlockingQueue<Object> blockingQueue = new LinkedBlockingDeque<>();

    public static void setConsole(ConsoleWork console) {
        ConsoleUtils.console = console;
        new Thread(() -> {

            while (true)
                try {
                    Object take = blockingQueue.take();
                    console.log(take);
                } catch (Exception e) {
                    e.printStackTrace();
                }
        }).start();
    }

    public static void log(Object object) {
        blockingQueue.offer(object);
    }

    public static void log() {
        blockingQueue.offer("");
    }


}
